package 共享锁;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

public class SemaphoreDemo {
    public static void main(String[] args) throws InterruptedException {
        final Semaphore sem = new Semaphore(0);
        for(int i=0; i<10; i++){
            final int j = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(j);
                    sem.release();//一个线程执行完，释放一个资源数
                }
            }).start();
        }
        sem.acquire(10);//此时我们要获取10个资源数，不到的话就一直阻塞
        System.out.println("main");
    }
}
